package com.imooc.security.filter;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ErrorHandler
 * @Description TODO 异常处理类
 * @Author wushaopei
 * @Date 2021/5/1 18:33
 * @Version 1.0
 */
@RestControllerAdvice
public class ErrorHandler {

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    public Map<String, Object> handler(Exception e){
        Map<String, Object> info = new HashMap<>();
        info.put("message", e.getMessage());
        info.put("time",new Date().getTime());
        return info;
    }
}
